package com.ch06;

public class ReturnDemo {
	public static void main(String[] args) { // (1) void method can use return.
		if (args.length == 0)
			output(checkValue(5));
		else
			output(checkValue(args.length));
	}

	static void output(int value) { // (2) void method need not use return.
		System.out.println(value);
		// return 'a'; // Not OK. Can not return a value.
	}

	static int checkValue(int i) { // (3) Non-void method: Any return statement
		// must return a value.
		if (i > 3)
			return i; // OK.
		else
			//return 2.0; // Not OK. double not assignable to int.
			return 2;
	}

	static int AbsentMinded() { // (4) Non-void method
		throw new RuntimeException(); // OK: No return statement provided, but
		// method terminates by throwing an exception.
	}
}